package com.itheima02.mapper;

import com.itheima.Student;
import com.itheima02.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentMapperImpl implements StudentMapper {
    SqlSession sqlSession = MyBatisUtils.getSqlSession();

    @Override
    public List<Student> selectAll() {
        List<Student> list = sqlSession.selectList("StudentMapper.selectAll");
        sqlSession.close();
        return list;
    }

    @Override
    public Student selectById(Integer id) {
        Student stu = sqlSession.selectOne("StudentMapper.selectById", id);
        sqlSession.close();
        return stu;
    }

    @Override
    public int insert(Student stu) {
        int res = sqlSession.insert("StudentMapper.insert", stu);
        sqlSession.close();
        return res;
    }

    @Override
    public int delete(Integer id) {
        int res = sqlSession.delete("StudentMapper.delete", id);
        sqlSession.close();
        return res;
    }

    @Override
    public int update(Student stu) {
        int res = sqlSession.update("StudentMapper.update", stu);
        sqlSession.close();
        return res;
    }
}
